package com.blb.marry.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

/**
 * @author lvtian
 * @date 2022/11/28 15:35
 */
@Controller
public class CodeController{

    @RequestMapping("/code")
    public void code(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(103, 38, 4, 2);
        captcha.write(response.getOutputStream());
        String code = captcha.getCode();
        System.out.println(code);
        request.getSession().setAttribute("code", code);
    }

}
